let server = 'http://m.wfhj171.com'
// let server = 'http://delaicloud.com:28001/wanfeng'
// let server = '/api'
let fetchUrl = 'http://m.wfhj171.com'
let fetchUrl1 = 'http://api.wfhj171.com'
import fetch from 'isomorphic-fetch'
let key = 'Xkwafeoa'
export default {
  key,
  server,
  async getData (url) {
    try {
      let res = await fetch(server + url, {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json',
        },
      });
      return await res.json();
    } catch (error) {
      console.log(error);
      return { errcode: 1, errmsg: 'JSON转化出错' };
    }
  },
  async getData1 (url) {
    try {
      let res = await fetch(fetchUrl1 + url, {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json',
        },
      });
      return await res.json();
    } catch (error) {
      console.log(error);
      return { errcode: 1, errmsg: 'JSON转化出错' };
    }
  },
  async post (url, body) {
    try {
      let result = await fetch(server + url, {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify(body),
      });
      return await result.json();
    } catch (error) {
      return { errcode: 1, errmsg: 'JSON转化出错' };
    }
  },
  async getFetchData (url) {
    try {
      let res = await fetch(fetchUrl + url, {
        method: 'GET',
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
        },
      });
      return await res.json();
    } catch (error) {
      console.log(error);
      return { errcode: 1, errmsg: 'JSON转化出错' };
    }
  },
  async fetchPost (url, body) {
    try {
      let result = await fetch(fetchUrl + url, {
        method: 'POST',
        mode: "no-cors",
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify(body),
      });
      return await result.json();
    } catch (error) {
      return { errcode: 1, errmsg: 'JSON转化出错' };
    }
  }
}


